package smartbooksdb.util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import smartbooksdb.exception.MandatoryFieldException;
import smartbooksdb.hibernatebean.User;

public class CommonFunctionsDB implements CommonConstantsDB {

	/**
	 * Converts the Date to String in the specified format
	 * 
	 * @param date
	 * @return dateString
	 */
	public static String toString(Date date) {
		DateFormat df = new SimpleDateFormat(DATE_FORMAT);
		return df.format(date.getTime());
	}

	/**
	 * Validates the username for null or blank value
	 * 
	 * @param username
	 * @throws MandatoryFieldException
	 */
	public static void validateUsername(String username)
			throws MandatoryFieldException {
		if (null == username || username.length() == 0) {
			throw new MandatoryFieldException(
					"Username cannot be null or blank");
		}
	}

	/**
	 * Validates the user for null value
	 * 
	 * @param user
	 * @throws MandatoryFieldException
	 */
	public static void validateUser(User user) throws MandatoryFieldException {
		if (null == user) {
			throw new MandatoryFieldException("User object cannot be null");
		} else {

		}
	}
}